<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>鑫多多</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link href="../css/icons-extra.css" rel="stylesheet" />
		<link href="../css/iconfont.css" rel="stylesheet" />
		<link href="../css/style.css" rel="stylesheet" />
		
		<style type="text/css">
			[ng-cloak] {
				display: none;
			}
			.mui-btn-royal.active{
				color: #fff !important;
				background-color:#8a6de9;
			}
		</style>

		<script src="../js/angular/angular.min.js"></script>
		<script src="../js/angular/angular-resource.js"></script>
		<script src="../js/angular/common.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/common.js"></script>
		<script src="../js/service/orderListService.js"></script>
		<script src="../js/service/goodsService.js"></script>
		<script src="../js/service/userService.js"></script>
	</head>

	<body ng-app="mainApp" ng-controller="orderListCtrl">
		<header class="mui-bar mui-bar-nav mui-bar-in">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<div style="margin: 0 60px 0 44px;padding-top: 2px;">
				<input type="search" class="mui-input-clear" ng-model="orderSearch" placeholder="请输入订单号">
			</div>
			<a class="mui-icon mui-pull-right right" ng-click="orderSearchBtn()">搜索</a>
		</header>
		<!-- 主页面内容容器 -->
		<div class="mui-content order-content mui-scroll-wrapper" id="pullrefresh">
			 <div class="mui-scroll">
			 	<!-- 主界面具体展示内容 -->
				<div class="mui-card order_wrap" >
					<ul class="mui-table-view">
	
						<li class="mui-table-view-cell mui-collapse  order" ng-repeat="order in orderList_" on-finish-render-filters>
							<a class="mui-navigate-right order_top" href="javascript:;">
								<span class="mui-pull-left mui-col-xs-7">订单:{{order.companyName}}</span>
								<span class="mui-pull-left mui-col-xs-3 username">{{order.userName}}</span>
								<span ng-if="order.status=='1'" class="mui-pull-right state mui-col-xs-2" style="color: green;">已交易</span>
								<span ng-if="order.status=='0'" class="mui-pull-right state mui-col-xs-2">未交易</span>
							</a>
							
							<ul class="mui-table-view cart order_con">
								<li class="">
									<p ng-if="order.expressCode!=null">&nbsp;&nbsp;&nbsp;物流单号：{{order.expressCode}}</p>
								</li>
								<li class="">
									<p ng-if="order.expressage!=null">&nbsp;&nbsp;&nbsp;物流跟踪：{{order.expressage}}</p>
								</li>
								<li class="mui-table-view-cell mui-media">
									<p ng-if="order.content!=null">&nbsp;&nbsp;&nbsp;订单备注：{{order.content}}</p>
								</li>
								<li class="mui-table-view-cell mui-media value_box" >
									<div class="order_btn">
										<button  class="mui-btn mui-btn-royal mui-btn-outlined  " ng-class="{'active':typeOneChecked==item.id}" ng-if="getTypeIfContain(item.id,order.gTypeOneIdlist)" ng-repeat="item in gTypeList"  ng-click="typeOneClick(item)" style="float:left; margin:5px;">{{item.title}}</button>
									</div>
								<li>
								<li class="mui-table-view-cell mui-media" >
									<div class="order_btn">
										<button  class="mui-btn mui-btn-royal mui-btn-outlined  " ng-if="getTypeIfContain(item.id,order.gTypeIdlist)" ng-repeat="item in typeList" ng-class="{'active':typeChecked==item.id}" ng-click="typeClick(item)" style="float:left; margin:5px;">{{item.typeName}}</button>
									</div>
								<li>
								<li class="mui-table-view-cell mui-media" ng-repeat="goods in order.goods" ng-show="(curTypeOne.id==null&&curType.id==null)||curTypeOne.id==goods.typeOne||curType.id==goods.type">
									<div class="mui-right" style=" border-bottom: none;" >
										<div class="mui-pull-left">
											<img  ng-show="goods.ifPic" class="mui-media-object"  src="{{baseUrl+'/dapi/download/getImageIO?imgUrl='+goods.iconUrl|getImgUrl}}"   name="imageClick" vale="{{goods.goodsId}}">
											<img  ng-show="!goods.ifPic" class="mui-media-object" ng-src="../images/goodsDefault.gif">
										</div>
										<div class="mui-media-body">
											<h5> <p >{{goods.goodsTitle}}</p>
												<p> 约{{goods.minWeight}}-{{goods.maxWeight}}g</p>
											</h5>
										</div>
										<img style="width: 50px;height: 50px;" ng-show="goods.phStatus==1" class="mui-media-object" ng-src="../images/right.png">
										<!--<img style="width: 50px;height: 50px;" ng-show="goods.phStatus==0" class="mui-media-object" ng-src="../images/wrong.png">-->
										<div class="mui-pull-right  price_box">
											<p class="mui-ellipsis">¥{{goods.dealPrice*goods.perWeight}}</p>
											<br>
											<p class="mui-ellipsis">×{{goods.dealNum}}</p>
											<br>
										</div>
									</div>
									<div class="mui-right">
										商品备注：{{goods.content}}
										<button ng-show="orderPerm" ng-if="order.status==0 && order.payStatus==1" class="mui-pull-right mui-btn mui-btn-primary mui-btn-outlined " ng-click="updatePhStatus(goods)"> 修改配货状态</button>
									</div>
	
								</li>
								<li class="mui-table-view-cell mui-media value_box">
									<span ng-if="order.payStatus=='1'" class=" state mui-col-xs-2" style="color: green;">已收款</span>
									<span ng-if="order.payStatus=='0'" class=" state mui-col-xs-2">未收款</span>
								</li>
								<li class="mui-table-view-cell mui-media value_box">
									<p class="total" id="{{order.orderId}}">共<strong> {{order.total}} </strong>件商品&nbsp;&nbsp;&nbsp;&nbsp;合计约/g：<strong> {{order.totalWeight}}g </strong></p>
									<div class="order_btn">
										<button type="button" ng-show="orderPerm" ng-disabled="order.status=='1'" class="mui-btn mui-btn-royal mui-btn-outlined" ng-click="updatePrice(order)">一键更新</button>
										<button type="button" ng-show="orderPerm" class="mui-btn mui-btn-royal mui-btn-outlined" ng-click="updateDealStatus(order)">完成交易</button>
										<button type="button" ng-show="orderPerm" class="mui-btn mui-btn-royal mui-btn-outlined" ng-click="updatePayStatus(order)">收款</button>
										<button type="button" ng-click="evaluate(order.orderId)" class="mui-btn mui-btn-primary mui-btn-outlined ">评价</button>
										<button type="button" class="mui-btn mui-btn-danger mui-btn-outlined " ng-click="deleteOrder(order)">删除</button>
									</div>
								</li>
							</ul>
						</li>
					</ul>
				</div>
			 </div>
			

		</div>
		<script type="text/javascript ">
			mui.init();

			mui('.bottomPopover').popover('toggle'); //show hide toggle
		</script>
		<script>
			(function($) {
				$.init({
					swipeBack: true //启用右滑关闭功能
				});
				$(".mui-scroll-wrapper").scroll({
					bounce: false, //滚动条是否有弹力默认是true
					indicators: true, //是否显示滚动条,默认是true
				});
			})(mui);
			mainApp.controller('orderListCtrl', function($scope, $http, orderListService,userService,goodsService) {
				
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							//callback: pulldownRefresh
						},
						up: {
							contentrefresh: '正在加载...',
							callback: pullupRefresh
						}
					}
				});
				
				function pullupRefresh() {
					setTimeout(function() {
						orderList();
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(); //refresh completed
					}, 1000);
				}
				
				
				$scope.baseUrl = baseUrl;
				$scope.pageIndex = 1;
				$scope.pageSize = 15;
				$scope.orderList_=null;
				var orderList=function(){
					orderListService.getOrderList({orderId:$scope.orderSearch}, $scope.pageIndex, $scope.pageSize, function(data) {
						var orderList=data.data.list;
						angular.forEach(orderList, function(order) {
							var total=0;
							angular.forEach(order.goods, function(goods) {
								total+=goods.dealNum;
								order.total=total;
							});
						});
						if($scope.pageIndex == 1){
							$scope.orderList_=orderList;
						}else{
							angular.forEach(orderList, function(order) {
								$scope.orderList_.push(order);
							});
						}
						if(orderList.length>0){
							$scope.pageIndex = $scope.pageIndex + 1;
						}
					}, error)
				}
				orderList();
				
				$scope.evaluate=function(orderId){
					mui.openWindow({
						url:'evaluateList.html',
						id:'evaluateList',
						extras:{
							orderId:orderId
						}
					});
				}
				userService.getUserDetail(function(data){
					$scope.orderPerm=false;
					angular.forEach(data.data.permCodeList,function(perm){
						if(perm=="orderManager"){
							$scope.orderPerm=true;
						}
					})
				},error)
				//更新订单金价价格
				$scope.updatePrice=function(order){
					$scope.ord={"orderId":order.orderId,"goods":order.goods}
					var btnarr=["确定","取消"];  
			       mui.confirm("单价更改后不能撤回是否确认？","操作提示",btnarr,function(e){  
			          if(e.index == 0){  
						orderListService.updatePrice($scope.ord,function(data){
						},error)
			          }
			       });  
				}
				//提交收款状态
				$scope.updatePayStatus=function(order){
				   var btnarr=["确定","取消"];  
			       mui.confirm("订单支付状态更改后不能撤回是否确认？","操作提示",btnarr,function(e){  
			          if(e.index == 0){  
						var payStatus="1";
						orderListService.updatePayStatus(order.orderId,payStatus,function(data){
							order.payStatus=payStatus;
						},error)
			          }
			       });  
				}
				//提交交易状态
				$scope.updateDealStatus=function(order){
					var btnarr=["确定","取消"];  
			       mui.confirm("订单交易状态更改后不能撤回是否确认？","操作提示",btnarr,function(e){  
			          if(e.index == 0){  
			            var dealStatus="1";
						orderListService.updateDealStatus(order.orderId,dealStatus,function(data){
							order.status=dealStatus;
						},error)
			          }
			       });  
				}
				//修改配货状态
				$scope.updatePhStatus=function(goods){
					var phStatus=goods.phStatus;
                    $scope.goods=goods;
                    if(phStatus==1){
                        $scope.goods.phStatus=0;
                        orderListService.updatePhStatus(goods,function () {
                        },error)
                    }else if(phStatus==0){
                        $scope.goods.phStatus=1;
                        orderListService.updatePhStatus(goods,function () {
                        },error)
                    }
				}
				//删除订单
				$scope.deleteOrder=function(order){
					if((order.status=="1"&&order.payStatus=="1")||(order.status=="0"&&order.payStatus=="0")){
						//交易完成可以删除---逻辑删除
						orderListService.deleteOrderStatus(order.orderId,function(data){
							angular.forEach($scope.orderList_,function(item,index){
								if(order.orderId==item.orderId){
									$scope.orderList_.splice(index,1);
								}
							})
						},error);
					}else{
						//交易正在进行 不允许删除
						mui.alert("正在交易，不允许删除！");
					}
				}
				$scope.orderSearchBtn=function(){
					$scope.pageIndex=1;
					orderList();
				}
				$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
					mui(".mui-pull-left").on("tap",".mui-media-object",function(){

						var goodsid=this.getAttribute("vale");
						mui.openWindow({
							url:"goodsDetails.html",
							id:'goodsDetails'+new Date().getMilliseconds(),
						    extras:{
						        goodsId:goodsid
						    },
						    styles: {
								popGesture:"close"	
							}
						});
					});
				});
				goodsService.getGoogsTypeList(function(data){
					$scope.gTypeList=data.data;
				},error);
				$scope.typeOneClick=function(item){
					$scope.typeOneChecked=item.id;//一级选中
					$scope.typeChecked="";//二级选中
					$scope.typeList=item.typeList;
					$scope.curTypeOne=item;
					$scope.curType={};
				}
					
				$scope.typeClick=function(item){
					$scope.typeChecked=item.id;
					$scope.curType=item;
					$scope.curTypeOne={};
				}
				$scope.getTypeIfContain=function(id,ids){
					var flag=false;
					for(var i=0;i<ids.length;i++){
						if(id==ids[i]){
							flag=true;
							return flag;
						}
					}
					return flag;
				}
			});
		</script>
	</body>
</html>